﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace KGE
{
    public class Devices : IDisposable
    {
        Game game;

        public Util.HDTimer Timer = new Util.HDTimer();

        public GPU GPU;

        public Microsoft.DirectX.DirectSound.Device DSoundDev;
        public Microsoft.DirectX.DirectInput.Device DKeyboardDev;
        public Microsoft.DirectX.DirectInput.Device DMouseDev;

        public Devices(Game g)
        {
            game = g;
            if (game.GameControl is Form)
            {
                Form gameControl = (Form)game.GameControl;

                gameControl.Text = game.Name;
                gameControl.StartPosition = FormStartPosition.CenterScreen;
                gameControl.Size = game.Options.WindowSizePixel;
                if (game.Options.IsShowWindowBorder)
                {
                    gameControl.FormBorderStyle = FormBorderStyle.Sizable;
                }
                else
                {
                    gameControl.FormBorderStyle = FormBorderStyle.None;
                }
                //GameWindow.MaximizeBox = false;
                //GameWindow.MinimizeBox = false;
            }

            DSoundDev = new Microsoft.DirectX.DirectSound.Device();
            DSoundDev.SetCooperativeLevel(game.GameControl, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal);
            
            DKeyboardDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard);
            DKeyboardDev.Acquire();

            DMouseDev = new Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse);
            DMouseDev.Acquire();

            GPU = new GPU(game);
        }

        public void Dispose()
        {
            DSoundDev.Dispose();
            DKeyboardDev.Dispose();
            DMouseDev.Dispose();
            GPU.Dispoise();
            //GameControl.Dispose();
        }
    } 
}
